<template>
	<el-form class="form"  :model="form" ref="formRef" :rules="rules" label-width="120px"  size="small">
		<div class="form_box">
		<div class="title">信息</div>
			<el-row>
				<el-col :span="12">
					<el-form-item label="用户ID:" prop="userId">
						<el-input v-model="form.userId" placeholder="请填写用户ID" ></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="角色ID:" prop="roleId">
						<el-input v-model="form.roleId" placeholder="请填写角色ID" ></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="创建时间:" prop="createTime">
						<el-date-picker v-model="form.createTime" type="date" value-format="yyyy-MM-dd"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="修改时间:" prop="modifyTime">
						<el-date-picker v-model="form.modifyTime" type="date" value-format="yyyy-MM-dd"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="状态1-正常2-禁用:" prop="status">
						<el-select v-model="form.status" filterable>
							<el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
		</div>
	</el-form>
</template>
<script>
import global_ from "@/utils/GlobalDict";
import { modifySysUserRole,addSysUserRole } from "@/api/system/sysUserRole";
export default {
	props: {
		dataObj: {
			type: Object,
			default: new Object()
		},
	},
	filters: {
	},
	data(){
		return {
			form:new Object(),
			statusList:[],
			rules:{
				userId:[{required: true, message: '请填写用户ID', trigger: 'blur'},],
				roleId:[{required: true, message: '请填写角色ID', trigger: 'blur'},],
				createTime:[{required: true, message: '请填写创建时间', trigger: 'blur'},],
				modifyTime:[{required: true, message: '请填写修改时间', trigger: 'blur'},],
				status:[{required: true, message: '请填写状态1-正常2-禁用', trigger: 'blur'},],
			},
		}
	},
	methods:{
		save(){
			this.$refs['formRef'].validate((valid) => {
				if(valid) {
					this.doSave();
				}else{
					return null;
				}
			});
		},
		doSave(){
			if(this.form.id){
				modifySysUserRole(this.form).then(response => {
					this.saveCallBack(response);
				});
			}else{
				addSysUserRole(this.form).then(response => {
					this.saveCallBack(response);
				});
			}
		},
		saveCallBack(response){
			if(response.data.success){
				this.$notify({
					title: '提示',
					message: '操作成功',
					type: 'success',
					duration: 2000
				})
				this.closeDialog(1)
			}else{
				this.$notify({
					title: '提示',
					message: '操作失败',
					type: 'danger',
					duration: 2000
				})
			}
		},
		closeDialog(reload){
			this.$emit("closeDialog",reload);
		},
	},
	created(){
		this.statusList = global_.elSelectConverter(global_.status);
		this.form = this.dataObj;
	},
}
</script>
